#ifndef __MYLOGGER_H__
#define __MYLOGGER_H__

#include <log4cpp/OstreamAppender.hh>
#include <log4cpp/PatternLayout.hh>
#include <log4cpp/Category.hh>

#define LOG_WARN(msg)  cdm::Mylogger::getMylogger()->warn(__FILE__,__LINE__,__FUNCTION__,msg)
#define LOG_ERROR(msg)  cdm::Mylogger::getMylogger()->error(__FILE__,__LINE__,__FUNCTION__,msg)
#define LOG_INFO(msg)   cdm::Mylogger::getMylogger()->info(__FILE__,__LINE__,__FUNCTION__,msg)

#include <string>

using std::string;
using namespace log4cpp;

namespace cdm{
    

class Mylogger{
    
public:

    class AutoRelase{
    public:
        AutoRelase(){

        }
        ~AutoRelase(){
            if(_log){
                delete _log;
                _log = nullptr;
            }
        }
    };

public:

    static Mylogger* getMylogger();
    static void destroyLoger();

    void warn(const char * file, int line, const char * func, const char * msg);
    void warn(const char * file, int line, const char * func, const string  msg);

    void error(const char * file, int line, const char * func, const char * msg);
    void error(const char * file, int line, const char * func, const string msg);

    void info(const char * file, int line, const char * func, const char * msg);
    void info(const char * file, int line, const char * func, const string msg);

private:
    Mylogger();
    ~Mylogger(){
        Category::shutdown();
    }
    static Mylogger*    _log;
    static Category*    _root;
    static AutoRelase   _au;

};

}//end of cdm

#endif


